
"""
读取H5文件内容，并进行处理

"""
import sys 
sys.path.append("..") 
sys.path.append("./") 
sys.path.append("./model")

import h5py
from model.search.LocalFeatureSet2 import LocalFeatureSet2



def update_featureset():
    db_featureset = LocalFeatureSet2()
    db_featureset.set_feature_dir('/root/autodl-tmp/data/pitts30k/images/test/hfnet_features_queries/')
    db_featureset.read()
    
    # features = db_featureset.get_features()
    # for id,fd in features.items():
    #     del fd['keypoints']
    #     del fd['descriptors']
    
    db_featureset.saveas('/root/autodl-tmp/data/pitts30k/images/test/hfnet_features_queries2/')
    
update_featureset()

def clone_h5():
    feature_path = '/root/autodl-tmp/data/pitts30k/images/test/hfnet_features_db/features.h5.2'
    with h5py.File(str(feature_path), 'a') as fd:

        def vist_fun(name,obj):
            print("reading:" + name,end='\r')
            if not isinstance(obj, h5py.Group):
                return
            if 'keypoints' in obj.keys() or 'descriptors' in obj.keys() or 'global_descriptor' in obj.keys() :
                del obj['keypoints']
                del obj['descriptors']

                

        fd.visititems(vist_fun)
        fd.flush()
    print("End Read Features." )

# clone_h5()